﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Pantry.Commons
{
    public static class  Validates
    {
        static public bool IsNaturalNumber(string numberValue)
        {
            if (String.IsNullOrEmpty(numberValue))
            {
                return false;
            }
            var numberRegular = new Regex(@"^[0-9]+$");
            var result = numberRegular.IsMatch(numberValue);
            return result;
        }

        static public bool IsEmptyOrNumber(string numberValue)
        {
            if (String.IsNullOrEmpty(numberValue))
            {
                return true;
            }
            var numberRegular = new Regex(@"^[0-9]+$");
            var result = numberRegular.IsMatch(numberValue);
            return result;
        }

        static public string TrimDescription(string description, int maxLength)
        {
            if (description.Length <= maxLength)
            {
                return description;
            }

            for (var i = maxLength; i > maxLength - 20; i--)
            {
                if (description[i].ToString(CultureInfo.InvariantCulture) != " ") continue;
                maxLength = i;
                break;
            }

            description = description.Substring(0, maxLength + 1) + "...";
            return description;
        }
    }
}
